<?php $view->extend('forum/forum_template', 'content', array('title' => $thread->getTitle())); ?>


<?php if($user && $forum->canAddThreadReply($user->getGmLevel())):?>
<div class="col c12 buttonpanel">
<a href="#" class="uibutton" id="postReplyBtn"><?php echo $view->lang->get('forum')->get('reply')?></a>
</div>
<?php endif;?>

<div class="thread">



<?php $view->import('forum/pages', array('method' => 'thread', 'args' => array('title'=>$forum->getUrl(), 'id' => $thread->getID() ),'pages' => $pages, 'curPage' => $curPage  )); ?>



<?php if ($user_forum_mod):?>
<div class="col c12 thread_mod">
	<h4><a href="<?php echo $view->url->linkTo('Forum','mod', array('type'=>'thread', 'id' => $thread->getID(),'action' => 'delete' ))?>"><?php echo $thread->isDeleted() ? 'Undelete' : 'Delete'?> <?php echo $view->lang->get('forum')->get('thread')?></a></h4>

	<h4><a href="<?php echo $view->url->linkTo('Forum','mod', array('type'=>'thread', 'id' => $thread->getID(),'action' => 'lock' ))?>"><?php echo $thread->isLocked() ? 'Unlock' : 'Lock'?> <?php echo $view->lang->get('forum')->get('thread')?></a></h4>
	<h4><a href="<?php echo $view->url->linkTo('Forum','mod', array('type'=>'thread', 'id' => $thread->getID(),'action' => 'stick' ))?>"><?php echo $thread->isSticky() ? 'Unsick' : 'Sticky'?> <?php echo $view->lang->get('forum')->get('thread')?></a></h4>
</div>
<?php endif;?>
<div class="col c12 column_head">
	<div class="row">
		<div class="col c7">
			<h4><?php echo $view->lang->get('forum')->get('thread')?>: <?php echo $thread->getTitle()?></h4>
		</div>
		<div class="col c3">
			<h4><?php echo $view->lang->get('forum')->get('thread_by')?> <?php echo $thread->getFirstPost()->getUsername()?></h4>
		</div>
		<div class="col c2">
			<h4><?php echo $thread->getFirstPost()->getPostedSince()?></h4>
		</div>
	</div>
</div>


<?php $postId = $curPage * 15; foreach($posts as $post): $postId++;?>

<?php $ac = $post->getAccount(); ?>


<div class="col c12 t_head">
<p class="left">#<?php echo $postId?></p>
<p><?php echo sprintf($view->lang->get('forum')->get('posted_at'), $post->getPostedSince())?></p>
<p><?php echo sprintf($view->lang->get('forum')->get('updated_at'), $post->getEditedSince())?></p>

<?php if ($ac): ?>
	<?php if ($user_forum_mod):?>
		<p><a href="<?php echo $view->url->linkTo('Forum','mod', array('type'=>'post', 'id' => $post->getID(),'action' => 'delete' ))?>"><?php echo $post->isDeleted() ? 'Undelete' : 'Delete'?> Post</a></p>

	<?php endif;?>

	<?php if ($user && ($ac->getID() == $user->getID() || $user_forum_mod )):?>
		<p><a href="#" class="editpost" title="<?php echo $post->getID()?>">Edit</a></p>
	<?php endif;?>
	
	

<?php endif;?>
<p><a href="#" class="replypost" title="<?php echo $post->getID()?>"><?php echo $view->lang->get('forum')->get('reply')?></a></p>

</div>
<div class="col c12 post" id="post_<?php echo $post->getID()?>">
	<div class="row">
		<div class="col c2 user_stat">
			<?php if ($ac):?>
				<h4 class="username"><?php echo $ac->getUsername()?></h4>
				<img src="<?php echo $view->url->link('img/forum/user_64.png')?>" alt="User"/>
				<p class="<?php echo $ac ? 'gmlevel_'.$ac->getGmLevel() : ''?>"><?php echo $ac->getGlobalRankName()?></p>
			<?php endif;?>
			<div class="row">
			<div class="col c2">
				<div class="row">
					<div class="col c1"><?php echo $view->lang->get('forum')->get('posts')?>:</div>
					<div class="col c1"><?php echo $post->getUserPostCount()?></div>
				</div>
			</div>
			</div>
		</div>
		<div class="col c10">
			<?php $parent = $post->getParent(); if ($parent):?>
			<div class="row">
				<div class="col c10"><blockquote cite=""><span class="bqstart">&#8220;</span><h4><?php echo sprintf($view->lang->get('forum')->get('post_by'), $parent->getUsername())?></h4><?php echo $parent->getText()?><span class="bqend">&#8221;</span></blockquote></div>
			</div>
			<?php endif;?>
			<div class="row">
				<div class="col c10 <?php echo $ac ? 'gmlevel_'.$ac->getGmLevel() : ''?> postcontent"><?php echo $post->getText()?></div>
			</div>
		</div>
	</div>
</div>
<?php endforeach;?>



<?php $view->import('forum/pages', array('method' => 'thread', 'args' => array('title'=>$forum->getUrl(), 'id' => $thread->getID() ),'pages' => $pages, 'curPage' => $curPage  )); ?>




<?php if($thread->isLocked()): ?>
<div class="col c12">
	<div class="message warning">
		<p><?php echo $view->lang->get('forum')->get('thread_locked')?></p>
	</div>
</div>
<?php endif; ?>



<?php if ($user && (!$thread->isLocked() || $user_forum_mod) &&  $forum->canAddThreadReply($user->getGmLevel()) ): ?>



<?php echo $postForm?>
<div class="col c12" id="postingForm">
<?php echo $postForm->input('hidden','editID', null, array('id' => 'postEditId'))?>
<?php echo $postForm->input('hidden','postReplyId', null, array('id' => 'postReplyId'))?>


<h2><?php echo $view->lang->get('forum')->get('reply')?></h2>




<div class="row">

<div class="col c9">

<div class="row">
	<div class="col c2">
		<h4><?php echo $view->lang->get('forum')->get('reply')?></h4>
	</div>
	<div class="col c7">
	<div id="inReplyTo" style="display: none;">
		<blockquote><span class="bqstart">&#8220;</span><h4></h4><div></div><span class="bqend">&#8221;</span></blockquote>
	</div>
	<?php echo $postForm->textarea('text', null, array('cols' => 118, 'rows' => 15, 'id' => 'postText'))?>
	</div>
</div>
<div class="row">
	<div class="col c2">
		<h4><?php echo $view->lang->get('forum')->get('post')?></h4>	
	</div>
	<div class="col c7">
	<?php echo $postForm->input('submit','submit',$view->lang->get('forum')->get('post'))?>
	</div>
</div>


</div>

<div class="col c3">
<?php $view->import('forum/forum_post_help')?>
</div>


</div>



</div>
<?php echo $postForm->close()?>


<?php elseif($user && !$forum->canAddThreadReply($user->getGmLevel())): ?>
<div class="col c12"><div class="message warning"><p><?php echo $view->lang->get('forum')->get('thread_no_access')?></p></div></div>

<?php else: ?>

<div class="col c12"><div class="message info"><p><?php echo $view->lang->get('forum')->get('login_to_reply')?></p></div></div>
<?php endif;?>
</div>




<script type="text/javascript">
/* <![CDATA[ */
$(document).ready(function(){ 
	$('a.editpost').click(function () { 
		resetFields();
      var id = $(this).attr("title");
      var text = $('#post_' + id).find('.postcontent').html();

      $('#postEditId').val(id);

      $('#postText').text(text);
      $('html, body').animate({
          scrollTop: $("#postingForm").offset().top
      }, 1000);
       
    });
	$('a.replypost').click(function () { 
		resetFields();
	    var id = $(this).attr("title");
	    var text = $('#post_' + id).find('.postcontent').html();
	    var username = $('#post_' + id).find('.username').html();

	    
	    $('#inReplyTo').find('h4').html(username);
	    $('#inReplyTo').find('div').html(text);
	    $('#postReplyId').val(id);

	    $('#inReplyTo').show();

	    
	    $('html, body').animate({
	        scrollTop: $("#postingForm").offset().top
	    }, 1000);
	       
	});
	
    

	$('#postReplyBtn').click(function () { 
			resetFields();
	      $('html, body').animate({
	          scrollTop: $("#postingForm").offset().top
	      }, 1000);
	});


	function resetFields(){
		$('#postEditId').val('');
	    $('#postText').text('');
	    $('#inReplyTo').hide();
	    $('#postReplyId').val('');
	    $('#inReplyTo').find('h4').text('');
	    $('#inReplyTo').find('div').text('');
	}
	

});
/* ]]> */
</script>	
